package com.xxcxcxcx.xc_crop.common;

import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.ModList;

import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashMap;

public class Configuration {
    public static ForgeConfigSpec commonConfig;
    public static HashMap<String,ForgeConfigSpec.ConfigValue<String>> Config = new HashMap<>();
    public static HashMap<ForgeConfigSpec.ConfigValue<String>,ArrayList<String>> configValueArrayListHashMap=new HashMap<>();
    public static ArrayList<String> whitelistStrtoArraylist(ForgeConfigSpec.ConfigValue<String> Basewhitelist){
        ArrayList<String> s=configValueArrayListHashMap.get(Basewhitelist);
        if(s==null){
            configValueArrayListHashMap.put(Basewhitelist,whitelistStrtoArraylist(Basewhitelist,0));
            s=configValueArrayListHashMap.get(Basewhitelist);
        }
        return s;
    }

    public static ArrayList<String> whitelistStrtoArraylist(ForgeConfigSpec.ConfigValue<String> Basewhitelist,int num)
    {
        ArrayList<String> whiteArraylist = new ArrayList<>();
        if(Basewhitelist==null)return whiteArraylist;
        String whitelist = Basewhitelist.get();
        String[] whiteBiomes = whitelist.split(",| ");
        for (String whiteBiome:
                whiteBiomes) {
            if(!whiteBiome.isEmpty())
            {
                whiteArraylist.add(whiteBiome);
            }
        }
        return whiteArraylist;
    };
    static {
        ForgeConfigSpec.Builder commonBuilder = new ForgeConfigSpec.Builder();
        commonBuilder.push("BiomesWhitelists");
        String[] strings={"wheat","bamboo","potato","sugarcane","carrot","cactus","beetroot",
                "acacia-sapling","birch-sapling","darkoak-sapling","jungle-sapling","oak-sapling","spruce-sapling",
                "SweetBerry","SeaPickle","NetherWart","Kelp","TwistingVines","Vine","WeepingVines","Melon","Pumpkin"};
        String[] farmstrings={"Cabbage","Onion","RicePanicles","Tomato"};
        for (int i=0;i<strings.length;i++){
            Config.put(strings[i],commonBuilder.comment("Biomes Whitelist for "+strings[i]+", use ',' to split").define(strings[i]+"BiomesWhitelist",""));
        }
        if(ModList.get().isLoaded("farmersdelight")) {
            for (int i=0;i<farmstrings.length;i++){
                Config.put(farmstrings[i],commonBuilder.comment("Biomes Whitelist for "+farmstrings[i]+", use ',' to split").define(farmstrings[i]+"BiomesWhitelist",""));
            }
        }
        commonBuilder.pop();
        commonConfig = commonBuilder.build();
    }
}
